package service

import (
	"context"
	"fmt"
	"youfu-log/pb"
)

type ProductService struct {
	pb.UnimplementedProductServiceServer
}

func (svc *ProductService) AddProduct(ctx context.Context, productId *pb.ProductModel) (*pb.ProductId, error) {
	fmt.Println("客户请求: AddProduct 方法")
	return &pb.ProductId{Value: "product_id_value"}, nil
}

func (svc *ProductService) GetProductById(ctx context.Context, productId *pb.ProductId) (*pb.ProductModel, error) {
	fmt.Println("客户请求: GetProductById 方法")
	return &pb.ProductModel{Name: "Name" + productId.GetValue(), Code: "Code" + productId.GetValue()}, nil
}

func (svc *ProductService) GetProductList(ctx context.Context, request *pb.QuerySize) (*pb.ProductList, error) {
	fmt.Println("客户请求: GetProductById 方法")
	productList := make([]*pb.ProductModel, int(request.Size))
	for i := 0; i < int(request.Size); i++ {
		productList[i] = &pb.ProductModel{Name: fmt.Sprintf("Name%d", i), Code: fmt.Sprintf("Code%d", i)}
	}
	fmt.Println("客户请求: GetProductList 方法")
	return &pb.ProductList{Values: productList}, nil
}
